package com.health.framework.service;

import java.io.Serializable;
import java.util.List;

import org.springframework.dao.DataAccessException;

import com.health.framework.dao.BaseDao;

public abstract class BaseService<E, PK extends Serializable> {

    protected abstract BaseDao<E, PK> getEntityDao();

    public E findById(PK pk) throws DataAccessException {
        return (E) getEntityDao().get(pk);
    }

    public List<E> findAll() throws DataAccessException {
        return getEntityDao().getAll();
    }

    public void save(E e) throws DataAccessException {
        getEntityDao().save(e);
    }

    public void removeById(PK pk) throws DataAccessException {
        getEntityDao().delete(pk);
    }

    public void update(E e) throws DataAccessException {
        getEntityDao().update(e);
    }

    public boolean isUnique(E e, String key) throws DataAccessException {
        return getEntityDao().isUnique(e, key);
    }

}
